/**
 * 
 */
package com.tjyx.maintain.dao;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.tjyx.common.util.db.DBConnector;
import com.tjyx.maintain.dto.NewsClass;

/**
 * @author liuyuxin
 *
 */
public class NewsClassDao {
	private Connection connection;
	
	public NewsClassDao(){
		connection=DBConnector.getConnection();
	}
	
    public void addNewsClass(String newsClassName) throws SQLException{
    	Statement statement=connection.createStatement();
    	statement.executeUpdate(" insert into eps_newclass(newClassName) values('"+newsClassName+"')");
    }	
    
    public void updateNewsClass(int id,String newsClassName) throws SQLException{
    	Statement statement=connection.createStatement();
    	statement.executeUpdate("update eps_newclass set newClassName='"+newsClassName+"' where newClassId="+id);
    }	
    
    public void deleteNewsClass(int id) throws SQLException{
    	Statement statement=connection.createStatement();
    	statement.executeUpdate(" delete  from eps_newclass where newClassId='"+id+"'");
    }	
    
    public List<NewsClass> queryNewsClass() throws SQLException{
    	Statement statement=connection.createStatement();
    	ResultSet rs=statement.executeQuery("select * from eps_newclass");
    	 List<NewsClass> list=new  ArrayList<NewsClass>();
    	while(rs.next()){
    		int id=rs.getInt(1);
    		String name=rs.getString(2);
    		NewsClass newsClass=new NewsClass();
    		newsClass.setNewClassId(id);
    		newsClass.setNewClassName(name);
    		list.add(newsClass);
    	}
    	return list;
    }	


}
